#!/usr/bin/perl

use lib qw(/usr/lib/libDrakX);
use MDK::Common;
use detect_devices;
use c;

system("mount -t proc none /proc");
my ($device) = cat_("/proc/mounts") =~ m!(/dev/\S+)\s+/initrd/cdrom\s+iso9660!;
system("umount /proc");
$device or exit;

# try to put halt/reboot in cache, if not called directly from them
system("$_ --help 2>/dev/null") foreach qw(halt reboot);

my $f = detect_devices::tryOpen($device);
# see openCdromTray() and unlockCdrom(), from install_any
ioctl($f, c::CDROM_LOCKDOOR(), 0);
ioctl($f, c::CDROMEJECT(), 0);

print "\n\nVyjměte prosím CD z mechaniky a stiskněte <Enter>.\n";
system "stty", 'eol', "\001";
$key = getc(STDIN);
system "stty", 'eol', '^@'; # ascii null

ioctl($f, 0x5319, 0); # CDROMCLOSETRAY

system("/initrd$ARGV[0] -i -d -p");
